<?php if(0):?><script type="text/javascript" src="/public/tinymce/tinymce.min.js"></script><?php endif;?>
<script type="text/javascript">
<?php if(0):?>
tinymce.init({
    selector: "textarea.editor",
    language:'zh_CN',
    menubar :false,
    height :300,
    plugins: [
        "advlist autolink lists link image charmap print preview anchor bbcode",
        "searchreplace visualblocks code fullscreen",
        "insertdatetime media table contextmenu paste moxiemanager"
    ],
    toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | table charmap searchreplace | cut copy paste print preview | removeformat code fullscreen"
});
<?php endif;?>
jQuery(function($){
    $(document.workpub).validation();
})
</script>
<form name="workpub" method="post" class="workpublish">
<div class="clearfix textline">
<label>主题：</label>
<input type="text" class="text" name="title" required="required" requiretip="请填写作品主题" />
</div>
<div class="clearfix textline">
<label>图片：</label><div class="imageviewbox"><input type="hidden" name="imagedefault" id="imagedefault" />
<input type="hidden" name="imageall" id="imageall" /><a href="javascript:;" onclick="moxman.browse({oninsert: function(a){insertImage(document.workpub.imageall,a)},no_host: true,multiple:true});" class="selectbtn">选择</a>
</div>
</div>
<div class="clearfix editline">
<label>故事：</label><label><input type="checkbox" name="iscomm" value="1" />&nbsp;推荐作品</label>
<div class="clear"></div>
<textarea name="content" class="editor"></textarea>
</div>
<div class="submitline">
    <input type="submit" class="ani button" name="submit" value="发表故事" />
</div>
</form>
<script type="text/javascript" >
function insertImage(field,files){
    var images=[];
    if(field.value){
        images=field.value.split(',');
    }
    for(var i=0;i<files.files.length;i++){
        if(!in_array(images,files.files[i].url)){
            images.push(files.files[i].url);
            renderfile(files.files[i],field);
        }else{
            tip('图片 '+ files.files[i].name +' 已添加过了',1,2);
        }
    }
    field.value=images.join(',');
}
function renderfile(file,field){
    $(field).before('<div class="imageview"><input type="hidden" name="image[]" value="'+file.url+'" /><img src="'+file.thumbnailUrl+'" alt=""/><a href="javascript:" class="ibtn defaultibtn" onclick="setDefault(this)">默认</a><a href="javascript:" class="ibtn" onclick="removeImg(this)">移除</a></div>');
    if(document.workpub.imagedefault.value==''){
        document.workpub.imagedefault.value=file.url;
        $('.imageviewbox .imageview').eq(0).addClass('default');
    }
}
function in_array(arr,value){
    for(var i=0;i<arr.length;i++){
        if(value==arr[i]){
            return true;
        }
    }
    return false;
}
function setDefault(obj){
    var view=$(obj).parents('.imageview').eq(0);
    $('.imageviewbox .imageview').removeClass('default');
    view.addClass('default');
}
function removeImg(obj){
    var view=$(obj).parents('.imageview').eq(0);
    if(confirm('您确定移除此图片？')){
        var isdefault=false;
        if(view.is('.default')){
            isdefault=true;
        }
        view.remove();
        setDefault($('.imageviewbox .defaultibtn').eq(0));
    }
}
</script>